﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>创建盘点任务</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
	<script src="~/js/framework/sysframework.js"></script>
	<script src="~/js/framework/commonjs.js"></script>
</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button id="btn-update" type="button" name="btn_update" onclick="saveData()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1005;</i>确定保存
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button id="btn-sync" type="button" onclick="closeWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1007;</i> 关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-card" >
        <div class="layui-card-body" style="padding-top:2%">
            <form id="dForm" class="layui-form layui-col-space5">
                <div class="layui-form-item" style="margin-left:1%">
                    <label for="L_email" class="layui-form-label">
                     盘点类型
                    </label>
                    <div class="layui-input-inline">
                    <input type="checkbox" name="doType" id="doType" title="ERP盘点" lay-skin="tag" checked>
                    </div>
                    <label for="L_email" class="layui-form-label">
                        盘点类别
                    </label>
                    <div class="layui-input-inline">
                        <select name="chType" id="chType" lay-filter="types">
                            <option value="">选择类型</option>
                        </select>
                    </div>
                </div>
     
                <div class="layui-form-item" style="margin-left:1%">

                    <label for="L_email" class="layui-form-label">
                    选择仓库
                    </label>
                    <div class="layui-input-inline" >
                        <select name="wareCode" id="wareCode" lay-filter="chWh">
                            <option value="">仓库信息</option>
                        </select>
                    </div>

                    <div class="layui-input-inline" id="pstDiv">
                        <select name="pstCode" id="pstCode" lay-filter="chPst">
                            <option value="">货位选择</option>
                        </select>
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" lay-filter="sreach" type="button" onclick="search()"><i class="layui-icon">&#xe615;</i></button>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-card-body" id="layui-table-main" style="float:left;background-color:#fff;margin-top:1%">
            <table class="layui-hide" id="list" lay-filter="list"></table>  
        </div>
    </div>


</body>
</html>
<script type="text/javascript">
    var list = [];
    var chType = "pc-ware";//盘点类型
    var err = 0;

    $(function () {
        var dataId = getUrlVariable("dataId");
        DictionaryDropDown("ppct", "chType", "");
        WareHouseSelect("wareCode");
        $('#pstDiv').hide();
    });

    layui.use(['layer', 'jquery', 'form'], function () {
        var form = layui.form;
        form.on('select(types)', function (data) {
            chType = data.value;
            if (chType == "pc-ware" || chType=="") {
                $('#pstDiv').hide();
            } else {
                $('#pstDiv').show();
            }
            getTableCloums(chType);
            loadData();
            // if ($('#doType').is(':checked') && chType != "") {
                
            // } 
        });
        form.on('select(chWh)', function (data) {
            var ck = data.value;
            if (ck != "") {
                WarePositionSelect("pstCode", ck);
            }
            loadData();
        });
        form.on('select(chPst)', function (data) {
            var ck = data.value;
            if (ck != "") {
                loadData();
            }
        
        });
    });

    function search() {
        loadData()
    }



    //仓库盘点 获取盘点单主表
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("dForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
                , cols: tCloumns
                , done: function (res, curr, count) {
                    if ($('#doType').is(':checked')) {
                        $("[data-field='dCount']").css('display', 'none');//隐藏列
                    } else {
                         $("[data-field='erpCode']").css('display', 'none');//隐藏列
                    }

                       
                }
                , url: "../ProCheck/GetDataList?dataType=erptasks&typesCode=" + chType + "&condition=" + conditon
                , skin: 'row' //表格风格
                , even: true
                , page: false //是否显示分页
                , limits: [20, 30, 50]
                , limit: 20 //每页默认显示的数量
                , id: "tData"
            });

            //监听工具条
            table.on('checkbox(list)', function (obj) {
                var checkStatus = table.checkStatus('tData');
                var datas = checkStatus.data;
                err = 0;
                list = [];
                for (var i = 0; i < datas.length; i++) {
                    if (list.length > 0) {
                        if (datas[i].code != list[0]["erpCode"]) {
                            layer.msg("只能选择一条记录信息", {icon:2});
                            err = 1;
                            return;
                        }
                    }
                    list.push(datas[i]);
                }

            });
        });
    }

    // 保存数据
    function saveData() {
        if (!err) {
            if (list.length < 1) {
                layer.msg("请先选择盘点单", { icon: 2 }); return;
            }
            var loadwin = layer.load(2, {
                shade: [0.3, '#424242'],
                content: '生成中',
                success: function (layerContentStyle) {
                    layerContentStyle.find('.layui-layer-content').css({
                        'padding-top': '35px',
                        'text-align': 'left',
                        'width': '120px'
                    });
                }
            }, { shadeClose: true });
            var datas = JSON.stringify(list);
            let erpCheck="N"
            if ($('#doType').is(':checked')) {
                erpCheck = "Y";
            }
            $.ajax({
                url: '../ProCheck/CreateTask',
                data: { datas: datas, chType: chType, erpCheck: erpCheck },
                dataType: "json",
                type: "POST",
                success: function (data) {
                    layer.close(loadwin);
                    if (data.result) {
                        layer.msg("盘点任务创建成功", { icon: 1 });
                    } else {
                        layer.msg(data.message, { icon: 2 });
                    }

                }
            });

        }
    }


    layui.use(['laydate'], function () {
        var $ = layui.$;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var max = null;
        var start = laydate.render({
            elem: '#rDatetime',
            trigger: 'click',
            type: 'datetime',
            format: 'yyyy/MM/dd',
            btns: ['clear', 'confirm'],

            done: function (value, date) {

            }
        });

    })

</script>